<?php

namespace app\api\controller;
use hg\apidoc\annotation as Apidoc;
use app\admin\model\Banner as BannerModel;
use app\admin\model\Goods;
use app\Request;

; 

/**
 * 首页
 */
class Home extends ApiBase
{
    
    /**
     * 新品速递
     *
     * @param Request $request
     * @return void
     */
    public function get_new_goods(Request $request){
        $list = Goods::where('is_del', 0)
            ->where('is_show',1)
            ->order('is_new desc, id desc')
            ->field('id as goods_id, store_name, image,goods_type')
            ->limit(10)
            ->select()
            ->toArray();
        return app('json')->success('ok',$list);
    }

    /**
     * 商品列表
     *
     * @return void
     */
    public function get_hot_goods(Request $request){
        $page = $request->get('page', 1);
        $limit = $request->get('limit', 10);
        $cate_id = $request->get('cate_id', '');
        $where = [];
        if ($cate_id) {
            $where[] = ['cate_id', '=', $cate_id];
        }
        $list = Goods::with(['artist','cate'])->where('is_del', 0)
            ->where('is_show',1)
            ->order('is_hot desc,sort desc, id desc')
            ->field('id, store_name, image,goods_type,artist_id,price,cate_id')
            ->where($where)
            ->page($page,$limit)
            ->select();
        return app('json')->success('ok',$list);
    }
}